package com.wiken.userservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wiken.servicecommon.common.Code;
import com.wiken.servicecommon.common.R;
import com.wiken.userservice.entity.Administrator;
import com.wiken.userservice.service.impl.AdministratorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wiken
 * @since 2023-01-18
 */
@RestController
@RequestMapping("/userservice/administrator")
public class AdministratorController {

    @Autowired
    AdministratorServiceImpl administratorService;

    @PostMapping("login")
    public R login(@RequestBody Administrator administrator){
        String token = administratorService.login(administrator);

        //TODO 获取管理员的更多信息去返回给前端

        if(token == null) R.error().code(Code.ERROR_LOGIN_PWD_USERNAME).message("用户或密码错误");

        return R.ok().code(Code.SUCCESS).message("登陆成功").data("token", token);
    }

    @PostMapping("getAdministratorById")
    public Boolean getAdministratorById(@RequestBody String id){
        Administrator administrator1 = administratorService.getById(id);

        return administrator1 != null;
    }
}
